<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div>
            <span>名</span>
            <span>
                <input type="text" v-model="firstName">
            </span>
        </div>
        <div>
            <span>姓</span>
            <span>
                <input type="text" v-model="lastName">
            </span>
        </div>
        <div>{{fullName}}</div>


    </div>
    <script src="../js/vue.min.js"></script>
    <script>
        // 侦听器用于处理异步或者开销较大的操作
        // 数据一旦出现变化就执行侦听器所绑定的方法
        let vm = new Vue({
            el: '#app',
            data: {
                firstName: 'Jim',
                lastName: 'Green',
                fullName: 'Jim Green'
            },
            watch: {
                firstName: function(val) {
                    this.fullName = val + ' ' + this.lastName
                },
                lastName: function(val) {
                    this.fullName = this.firstName + ' ' + val
                }
            }
        })
    </script>
</body>

</html>